import request from '@/utils/request'

/**
 * 获取应付账单列表
 * @param {Object} params - 查询参数
 */
export function getPayableList(params) {
  return request({
    url: '/crm/api/payables/',
    method: 'get',
    params
  })
}

/**
 * 获取应付账单详情
 * @param {Number} id - 账单ID
 */
export function getPayableDetail(id) {
  return request({
    url: `/crm/api/payables/${id}/`,
    method: 'get'
  })
}

/**
 * 创建应付账单
 * @param {Object} data - 账单数据
 */
export function createPayable(data) {
  return request({
    url: '/crm/api/payables/create/',
    method: 'post',
    data
  })
}

/**
 * 从采购单创建应付账单
 * @param {Object} data - 采购单数据
 */
export function createPayableFromPurchase(data) {
  return request({
    url: '/crm/api/payables/create-from-purchase/',
    method: 'post',
    data
  })
}

/**
 * 更新应付账单
 * @param {Number} id - 账单ID
 * @param {Object} data - 更新数据
 */
export function updatePayable(id, data) {
  return request({
    url: `/crm/api/payables/${id}/update/`,
    method: 'put',
    data
  })
}

/**
 * 删除应付账单
 * @param {Number} id - 账单ID
 */
export function deletePayable(id) {
  return request({
    url: `/crm/api/payables/${id}/`,
    method: 'delete'
  })
}

/**
 * 标记账单为已付款
 * @param {Number} id - 账单ID
 * @param {Object} data - 付款信息
 */
export function markAsPaid(id, data) {
  return request({
    url: `/crm/api/payables/${id}/mark-paid/`,
    method: 'post',
    data
  })
}

/**
 * 上传付款凭证/附件
 * @param {Number} id - 账单ID
 * @param {Object} data - 文件ID列表
 */
export function uploadAttachments(id, data) {
  return request({
    url: `/crm/api/payables/${id}/attachments/`,
    method: 'post',
    data
  })
}

/**
 * 删除附件
 * @param {Number} id - 账单ID
 * @param {Number} fileId - 文件ID
 */
export function removeAttachment(id, fileId) {
  return request({
    url: `/crm/api/payables/${id}/attachments/${fileId}/`,
    method: 'delete'
  })
}

/**
 * 获取供应商列表
 */
export function getSuppliers() {
  return request({
    url: '/crm/api/payables/suppliers/',
    method: 'get'
  })
}

/**
 * 快速创建供应商
 * @param {Object} data - 包含name的对象
 */
export function quickCreateSupplier(data) {
  return request({
    url: '/crm/api/payables/suppliers/quick-create/',
    method: 'post',
    data
  })
}

/**
 * AI识别发票信息
 * @param {Object} data - 包含image_url的对象
 */
export function recognizeInvoice(data) {
  return request({
    url: '/crm/api/payables/recognize-invoice/',
    method: 'post',
    data
  })
}

/**
 * AI识别支付截图信息
 * @param {Object} data - 包含image_url的对象
 */
export function recognizePayment(data) {
  return request({
    url: '/crm/api/payables/recognize-payment/',
    method: 'post',
    data
  })
}
